Skip to content

Write YOLO Detector and Drawer#1

Merged
FelonEkonom merged 28 commits intomasterfrom
implementation
Dec 4, 2025
Merged

Write YOLO Detector and Drawer#1
FelonEkonom merged 28 commits intomasterfrom
implementation

Conversation

@FelonEkonom
Copy link
Copy Markdown
Member

No description provided.

@FelonEkonom FelonEkonom requested a review from mat-hek November 24, 2025 16:29
@FelonEkonom FelonEkonom moved this from In Progress to In Review in Smackore Nov 24, 2025
@FelonEkonom FelonEkonom removed the request for review from mat-hek November 24, 2025 16:30
@FelonEkonom FelonEkonom requested a review from mat-hek November 24, 2025 16:59
Copy link
Copy Markdown
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples aren't adjusted to changes in the raw video format

.gitignore Outdated

# Created by https://www.gitignore.io/api/c,vim,linux,macos,elixir,windows,visualstudiocode
# Edit at https://www.gitignore.io/?templates=c,vim,linux,macos,elixir,windows,visualstudiocode
# Edit at https://www.gitignore.io/?yolos=c,vim,linux,macos,elixir,windows,visualstudiocode
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xd

@mat-hek mat-hek self-requested a review November 26, 2025 14:16
@@ -0,0 +1,337 @@
# Membrane YOLO Plugin demos

```elixir
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add this, so there's better chance that cargo is found and Ortex compiles on Mac

Suggested change
```elixir
```elixir
System.put_env("PATH", "/opt/homebrew/bin:#{System.get_env("PATH")}")

## Download fixtures and model

```elixir
tmp_dir = System.tmp_dir!()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a subdir, such as tmp_dir/membrane_yolo_examples


classes_path = tmp_dir |> Path.join("coco_classes.json")

classes_json = """
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're downloading model and samples, we can download classes.json as well


<!-- livebook:{"branch_parent_index":0} -->

## Live objec detection on a stream from the comptuer camera
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Live objec detection on a stream from the comptuer camera
## Live object detection on a stream from the local camera

end
```

... and run it. After up to few seconds a player showing the stream with bouncing boxes should appear.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that the player window may be not visible

Comment on lines +69 to +85
defp maybe_draw_boxes(buffer, detected_objects, state) do
case state.draw_boxes do
false ->
%Membrane.Buffer{
buffer
| metadata: Map.put(buffer.metadata, :detected_objects, detected_objects)
}

draw_fun when is_function(draw_fun, 2) ->
{:ok, image} =
Membrane.RawVideo.payload_to_image(buffer.payload, state.stream_format)

image = draw_fun.(image, detected_objects)
{:ok, new_payload, _stream_format} = Membrane.RawVideo.image_to_payload(image)
%Membrane.Buffer{buffer | payload: new_payload}
end
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated between the offline and live filter. We can make the function public

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code is rewrited due to moving draw_detected_objects function to our codebase. There is some place for remove code duplication, but IMO after recent changes it would only make the code more complicated if we want to avoid unnecessary conversions between raw video binary and Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's worth having a separate offline filter. It's just the live filter but we wait until a buffer is processed each time. We could have a mode: :live | :offline option instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I have added another option to Live Filter. The reason why I have decided to have two filters, is because the Live one has some options that won't make any sense in Offline scenario

function from [kino_yolo](https://github.com/poeticoding/kino_yolo)
"""
],
additional_latency: [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it shouldn't be the responsibility of this element, we could have a separate filter that would just add latency and would be usable in all cases like this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but TBH I don't see any advantage of using such an element beyond this scenario.
The behaviour we want to get could be done by adding an element that sleeps on start of stream for additional_latency and then realtimer after it, but figuring this out is not trivial so embedding the solution of this problem somehow in this plugin sounds like a good idea IMO

lib/utils.ex Outdated
Comment on lines +1 to +20
# defmodule Membrane.YOLO.Utils do
# @moduledoc false

# @spec draw_boxes_or_update_metadata(
# buffer :: Membrane.Buffer.t(),
# detected_objects :: [map()],
# draw_boxes :: false | (Vix.Vips.Image.t(), [map()] -> Vix.Vips.Image.t())
# ) :: Membrane.Buffer.t()

# def draw_boxes_or_update_metadata(buffer, detected_objects, false) do
# metadata = buffer.metadata |> Map.put(:detected_objects, detected_objects)
# %Membrane.Buffer{buffer | metadata: metadata}
# end

# def draw_boxes_or_update_metadata(buffer, detected_objects, draw_fun)
# when is_function(draw_fun, 2) do
# new_payload = draw_fun.(buffer.payload, detected_objects)
# %Membrane.Buffer{buffer | payload: new_payload}
# end
# end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Comment on lines +44 to +45
The simplest way to draw boxes is to pass `KinoYOLO.Draw.draw_detected_objects/2`
function from [kino_yolo](https://github.com/poeticoding/kino_yolo)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR we agreed to extract this from kino_yolo and improve colour contrast

@FelonEkonom FelonEkonom requested a review from mat-hek December 2, 2025 15:20
Copy link
Copy Markdown
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed:

  • Split detection and drawing into separate elements
  • Get rid of the GenServer
  • Consider merging live and offline elements

@FelonEkonom FelonEkonom changed the title Write YOLO Live and Offline filters Write YOLO Detector and Drawer Dec 3, 2025
@FelonEkonom FelonEkonom requested a review from mat-hek December 3, 2025 15:42
@FelonEkonom FelonEkonom removed the request for review from mat-hek December 3, 2025 15:47
@FelonEkonom FelonEkonom requested a review from mat-hek December 3, 2025 16:25
@FelonEkonom FelonEkonom merged commit 8b80663 into master Dec 4, 2025
1 of 3 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Smackore Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants